home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-04 | 6.0 KB | 154 lines | [TEXT/CCL ] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Copyright 1987, 1988, 1989, 1990 by Ruben Kleiman for Apple Computer, Inc.
- ;;; Advanced Technology Group
- ;;;
-
- ;;;
- ;;; This package allows you to communicate among Macintoshes using AppleTalk's
- ;;; ADSP (Asynchronous Data Stream Protocol) protocol. It also allows you
- ;;; to use AppleTalk name service NBP (Name Binding Protocol) protocol.
- ;;;
-
-
- ;;; Sample Networking Session
- ;;;
- ;;; Sample session between two virtual Mac's: MAC1 and MAC2
- ;;; You can emulate this session by entering the following forms into
- ;;; your Lisp listener. The prompts MAC1> and MAC2> designate
- ;;; the "virtual" Mac into whose listener you are theoretically typing.
- ;;; Note that we use AppleTalk's ability to send messages WITHIN a Macintosh
- ;;; to do this sample session.
- ;;;
- ;;; We will type forms into the Listener (within the :NETWORK package)
- ;;; which will show you how to processes in two machines can communicate
- ;;; with each other. The variable NETWORK::*MONITORING*, when set to a
- ;;; NON-NIL value, will cause monitoring information to be printed in
- ;;; your listener in response to some functions you may use (e.g., the ones
- ;;; that try to set up a connection). You may set this variable to NIL
- ;;; to prevent these messages from being printed.
- ;;;
- ;;; The general server/client architecture is as follows: you can create
- ;;; an object within your machine which acts as a server. A server, once
- ;;; created, registers itself in the network. You can create one or more
- ;;; client objects in other (or the same) machines, specifying which server
- ;;; each client object should be assumed to be connected with. The function
- ;;; TURN-SERVER-ON and TURN-CLIENT-ON are used to do this. Once a server
- ;;; or client object is successfully created, a connection between them
- ;;; is also automatically available. We call "partners" to be a server which is connected
- ;;; to a client: i.e., the server and client objects are said to be partners.
- ;;; Once a connection is established, the communications protocol is balanced:
- ;;; i.e., the server and clients have equal communications rights. It is possible
- ;;; to send and queue up multiple messages in either direction, or to send
- ;;; messages simultaneously in both directions.
- ;;;
-
- ;;;
- ;;; Partners communicate with each other via stream messages sent to the appropiate
- ;;; objects: e.g., (format client "Hello") will send the string "Hello" to the
- ;;; machine in which the client object is defined. It is important, however,
- ;;; the you use the FORCE-OUTPUT function to actually cause the message to
- ;;; be sent to the remote client or server. This allows you to internally
- ;;; queue up multiple messages before sending them.
- ;;;
-
-
-
- ? (require :adsp) ; THIS LOADS THE NECESSARY FUNCTIONS
- ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Network:ADSP.lisp"...
- ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Library:TRAPS.fasl"...
- ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Network:NETWORK-DEFS.fasl"...
- ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Network:DRIVER.fasl"...
- ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Network:NBP.fasl"...
- ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Servers:SERVER.fasl"...
- ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Events:EVENT.fasl"...
- "ADSP"
-
- ? (in-package :network) ; MAKE SURE YOU EVALUATE THIS ONE IN THE LISTENER WINDOW!!!
- #<PACKAGE "NETWORK">
-
- MAC1> (init-adsp) ; THIS INITIALIZES THE ADSP DRIVER
- T
- ;;; THE FOLLOWING FORM IS USED TO CREATE A SERVER NAMED "Ruben" WHOSE TYPE IS "Cool Dudes"
- ;;; THE SERVER COMMUNICATIONS MEDIUM IS SPECIFIED TO BE :ADSP (THE ONLY ONE CURRENTLY
- ;;; AVAILABLE IN THIS PACKAGE--YOU CAN WRITE YOUR OWN EXTENSIONS, E.G., TCP/IP, AND
- ;;; ADD THEM TO THIS SIMPLE SERVER ARCHITECTURE). THIS SERVER NOW EXISTS IN
- ;;; THE MAC1 MACINTOSH.
- MAC1> (turn-server-on :adsp :name "Ruben" :type "Cool Dudes")
-
- adsp server initialized on #<Object #169, a *ADSP-SERVER*>
- adsp server stream opened on #<Object #169, a *ADSP-SERVER*>
- #<Object #169, a *ADSP-SERVER*>
-
- ;;; THE FOLLOWING FORM CREATES A CLIENT IN THE MACINTOSH MAC2 FOR THE SERVER WE
- ;;; JUST CREATED IN MAC1. THE VARIABLE server IS HERE BOUND TO AN OBJECT WHICH STANDS
- ;;; FOR THE REMOTE SERVER: THAT IS, WE CAN TREAT server AS IF IT WERE THE REMOTE SERVER.
- ;;; WE WILL LATER USE server TO SEND MESSAGES TO THAT SERVER.
- MAC2> (turn-client-on server :adsp :server-name "Ruben" :server-type "Cool Dudes")
-
- adsp stream initialized on #<Object #176, a *ADSP-STREAM*>
- adsp stream connection requested on #<Object #176, a *ADSP-STREAM*>
- adsp st
- adsp stream initialized on #<Object #177, a *ADSP-STREAM*>
- adsp stream opened on #<Object #177, a *ADSP-STREAM*>
- About to accept conn
- adsp stream connection accepted on #<Object #177, a *ADSP-STREAM*>ream opened on #<Objec
- t #176, a *ADSP-STREAM*>
- NIL
-
- MAC2> server
- #<Object #176, a *ADSP-STREAM*>
-
- ;;; LET'S GET SERVER STATUS INFORMATION. THIS TELLS YOU WHETHER THE CONNECTION
- ;;; IS OPEN OR NOT, AND HOW MUCH SPACE IS ALLOCATED IN THE OUTGOING AND INCOMING
- ;;; MESSAGE QUEUES AS WELL AS HOW MUCH OF IT IS USED UP. (FOR THOSE WHO NEED
- ;;; TO KNOW, THIS INFORMATION IS THE ONE RETURNED BY THE ADSP DRIVER'S STATUS CALL
- ;;; AND IS DESCRIBED IN DETAIL IN THE ADSP PROGRAMMER'S MANUAL.)
- MAC2> (ask server (status))
- OPEN
- 0
- 30634
- 0
- 30634
-
- MAC1> (setq client (get-new-client :server-name "Ruben" :server-type "Cool Dudes"))
- #<Object #177, a *ADSP-STREAM*>
-
- MAC1> (ask client (status))
- OPEN
- 0
- 30634
- 0
- 30634
-
- ;;; Now let's send something from MAC1 to MAC2
-
- MAC1> (listen client) ; nothing pending to receive in MAC2
- NIL
-
- MAC2> (write-line "Hello MAC1!" server)
- "Hello MAC1!"
- MAC2> (force-output server) ; force buffer out to MAC1
- NIL
-
- MAC1> (listen client)
- T ; something has arrived at MAC1
-
- MAC1> (read-line client)
- "Hello MAC1!"
- NIL
-
- ;;; Now let's send something to MAC2
-
- MAC1> (write-string "Well, hello MAC2" client)
- Well, hello MAC2
- MAC1> (force-output client)
- NIL
-
-
- MAC2> (listen server)
- T
- MAC2> (read-line server)
- "Well, hello MAC2"
- T
-
-